1
|
|
|
/* |
2
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
3
|
|
|
* |
4
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Affero General Public License as published |
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Affero General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Affero General Public License |
17
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; |
21
|
|
|
|
22
|
|
|
export default class SingleLinePlugin extends Plugin { |
23
|
|
|
init() { |
24
|
|
|
const editor = this.editor; |
25
|
|
|
const view = editor.editing.view; |
26
|
|
|
const viewDocument = view.document; |
27
|
|
|
|
28
|
|
|
//Listen to enter presses |
29
|
|
|
this.listenTo( viewDocument, 'enter', ( evt, data ) => { |
|
|
|
|
30
|
|
|
//If user presses enter, prevent the enter action |
31
|
|
|
evt.stop(); |
32
|
|
|
}, { priority: 'high' } ); |
33
|
|
|
|
34
|
|
|
//And clipboard pastes |
35
|
|
|
this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => { |
36
|
|
|
let dataTransfer = data.dataTransfer; |
37
|
|
|
|
38
|
|
|
//Clean text input (replace newlines with spaces) |
39
|
|
|
let input = dataTransfer.getData("text"); |
40
|
|
|
let cleaned = input.replace(/\r?\n/g, ' '); |
41
|
|
|
|
42
|
|
|
//We can not use the dataTransfer.setData method because the old object is somehow protected |
43
|
|
|
data.dataTransfer = new DataTransfer(); |
|
|
|
|
44
|
|
|
data.dataTransfer.setData("text", cleaned); |
45
|
|
|
|
46
|
|
|
}, { priority: 'high' } ); |
47
|
|
|
} |
48
|
|
|
} |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.